home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / uhren & terminkalender / organizer / stickit2 / source / stickit2.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  8KB  |  295 lines

  1. /*********************************************/
  2. /*                                           */
  3. /*       Designer (C) Ian OConnor 1994       */
  4. /*                                           */
  5. /*      Designer Produced C include file     */
  6. /*                                           */
  7. /*********************************************/
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <intuition/screens.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/gfxbase.h>
  16. #include <workbench/workbench.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/wb_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/gadtools_protos.h>
  21. #include <clib/graphics_protos.h>
  22. #include <clib/utility_protos.h>
  23. #include <string.h>
  24.  
  25. #include "stickit2.h"
  26.  
  27.  
  28. struct Menu *commodMenu = NULL;
  29.  
  30. struct NewMenu commodMenuNewMenu[] =
  31.     {
  32.     NM_TITLE, (STRPTR)"Project"      ,  0 , 0, 0, 0,
  33.     NM_ITEM , (STRPTR)"Save"         , (STRPTR)"S", 0, 0, 0,
  34.     NM_ITEM , (STRPTR)"About..."     , (STRPTR)"?", 0, 0, 0,
  35.     NM_ITEM , (STRPTR)"Hide"         , (STRPTR)"H", 0, 0, 0,
  36.     NM_ITEM , NM_BARLABEL            ,  0 , 0, 0, 0,
  37.     NM_ITEM , (STRPTR)"Quit"         , (STRPTR)"Q", 0, 0, 0,
  38.     NM_TITLE, (STRPTR)"Notes"        ,  0 , 0, 0, 0,
  39.     NM_ITEM , (STRPTR)"New note"     , (STRPTR)"N", 0, 0, 0,
  40.     NM_ITEM , (STRPTR)"Delete note"  , (STRPTR)"D", 0, 0, 0,
  41.     NM_ITEM , NM_BARLABEL            ,  0 , 0, 0, 0,
  42.     NM_ITEM , (STRPTR)"Redraw notes" , (STRPTR)"R", 0, 0, 0,
  43.     NM_END  , NULL                   ,  0 , 0, 0, 0
  44.     };
  45.  
  46. ULONG commodMenuTags[] =
  47.     {
  48.     GT_TagBase+67, TRUE,
  49.     TAG_DONE
  50.     };
  51.  
  52. struct Menu *noteMenu = NULL;
  53.  
  54. struct NewMenu noteMenuNewMenu[] =
  55.     {
  56.     NM_TITLE, (STRPTR)"Project"           ,  0 , 0, 0, 0,
  57.     NM_ITEM , (STRPTR)"Save"              , (STRPTR)"S", 0, 0, 0,
  58.     NM_ITEM , NM_BARLABEL                 ,  0 , 0, 0, 0,
  59.     NM_ITEM , (STRPTR)"Commodities panel" , (STRPTR)"P", 0, 0, 0,
  60.     NM_TITLE, (STRPTR)"Edit"              ,  0 , 0, 0, 0,
  61.     NM_ITEM , (STRPTR)"Cut"               , (STRPTR)"X", 0, 0, 0,
  62.     NM_ITEM , (STRPTR)"Copy"              , (STRPTR)"C", 0, 0, 0,
  63.     NM_ITEM , (STRPTR)"Paste"             , (STRPTR)"V", 0, 0, 0,
  64.     NM_ITEM , (STRPTR)"Delete"            , (STRPTR)"B", 0, 0, 0,
  65.     NM_END  , NULL                        ,  0 , 0, 0, 0
  66.     };
  67.  
  68. ULONG noteMenuTags[] =
  69.     {
  70.     GT_TagBase+67, TRUE,
  71.     TAG_DONE
  72.     };
  73.  
  74. struct Window *commod = NULL;
  75. APTR commodVisualInfo;
  76. struct Gadget *commodGList;
  77. struct Gadget *commodGadgets[11];
  78.  
  79. STRPTR commod_cyccolourLabels[] =
  80. {
  81.     (STRPTR)"Background",
  82.     (STRPTR)"Text",
  83.     NULL
  84. };
  85.  
  86. ULONG commodGadgetTags[] =
  87.     {
  88.     GTLV_ShowSelected, 0,
  89.     GTLV_Selected, 0,
  90.     TAG_END,
  91.     GT_Underscore, '_',
  92.     TAG_END,
  93.     GT_Underscore, '_',
  94.     TAG_END,
  95.     GT_Underscore, '_',
  96.     TAG_END,
  97.     GT_Underscore, '_',
  98.     TAG_END,
  99.     GTPA_Depth, 0,
  100.     GTPA_IndicatorWidth, 30,
  101.     GA_Disabled, TRUE,
  102.     TAG_END,
  103.     GA_Disabled, TRUE,
  104.     GTCY_Labels, &commod_cyccolourLabels[0],
  105.     TAG_END,
  106.     GTST_MaxChars, 128,
  107.     GA_Disabled, TRUE,
  108.     GT_Underscore, '_',
  109.     TAG_END,
  110.     GTTX_Border, TRUE,
  111.     TAG_END,
  112.     GT_Underscore, '_',
  113.     GA_Disabled, TRUE,
  114.     TAG_END,
  115.     GA_Disabled, TRUE,
  116.     GT_Underscore, '_',
  117.     TAG_END,
  118.     };
  119.  
  120. UWORD commodGadgetTypes[] =
  121.     {
  122.     LISTVIEW_KIND,
  123.     BUTTON_KIND,
  124.     BUTTON_KIND,
  125.     BUTTON_KIND,
  126.     BUTTON_KIND,
  127.     PALETTE_KIND,
  128.     CYCLE_KIND,
  129.     STRING_KIND,
  130.     TEXT_KIND,
  131.     BUTTON_KIND,
  132.     STRING_KIND,
  133.     };
  134.  
  135. struct NewGadget commodNewGadgets[] =
  136.     {
  137.     4, 2, 226, 70, NULL, NULL, commod_listview, 1, NULL,  &commodGadgetTags[0],
  138.     4, 73, 50, 14, (UBYTE *)"_New", NULL, commod_new, 16, NULL,  &commodGadgetTags[5],
  139.     57, 73, 50, 14, (UBYTE *)"De_l", NULL, commod_del, 16, NULL,  &commodGadgetTags[8],
  140.     110, 73, 50, 14, (UBYTE *)"_Up", NULL, commod_up, 16, NULL,  &commodGadgetTags[11],
  141.     163, 73, 50, 14, (UBYTE *)"_Down", NULL, commod_down, 16, NULL,  &commodGadgetTags[14],
  142.     340, 37, 150, 15, NULL, NULL, commod_palette, 1, NULL,  &commodGadgetTags[17],
  143.     340, 20, 150, 14, (UBYTE *)"Note colours", NULL, commod_cyccolour, 1, NULL,  &commodGadgetTags[24],
  144.     340, 3, 150, 14, (UBYTE *)"_Title bar", NULL, commod_title, 1, NULL,  &commodGadgetTags[29],
  145.     340, 55, 150, 16, NULL, NULL, commod_fontstr, 1, NULL,  &commodGadgetTags[36],
  146.     236, 56, 100, 14, (UBYTE *)"_Font...", NULL, commod_font, 16, NULL,  &commodGadgetTags[39],
  147.     340, 74, 150, 14, (UBYTE *)"Pub. _Screen", NULL, commod_pubscreen, 1, NULL,  &commodGadgetTags[44],
  148.     };
  149. UWORD commodDepth;
  150.  
  151. int MakeMenucommodMenu( APTR MenuVisualInfo )
  152. {
  153.     if (NULL == (commodMenu = CreateMenusA( commodMenuNewMenu, NULL))) 
  154.         return( 1L );
  155.     LayoutMenusA( commodMenu, MenuVisualInfo, &commodMenuTags[0]);
  156.     return( 0L );
  157. }
  158.  
  159. int MakeMenunoteMenu( APTR MenuVisualInfo )
  160. {
  161.     if (NULL == (noteMenu = CreateMenusA( noteMenuNewMenu, NULL))) 
  162.         return( 1L );
  163.     LayoutMenusA( noteMenu, MenuVisualInfo, ¬eMenuTags[0]);
  164.     return( 0L );
  165. }
  166.  
  167. int OpenWindowcommod( struct MsgPort *mp)
  168. {
  169. struct Screen *Scr;
  170. UWORD offx, offy;
  171. UWORD loop;
  172. struct NewGadget newgad;
  173. struct Gadget *Gad;
  174. if (commod == NULL)
  175.     {
  176.     if (NULL != (Scr = LockPubScreen(NULL)))
  177.         {
  178.         ULONG scalex = 65535*Scr->RastPort.Font->tf_XSize/8;
  179.         ULONG scaley = 65535*Scr->RastPort.Font->tf_YSize/8;
  180.         offx = Scr->WBorLeft;
  181.         offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
  182.         if (NULL != ( commodVisualInfo = GetVisualInfoA( Scr, NULL)))
  183.             {
  184.             commodGList = NULL;
  185.             Gad = CreateContext( &commodGList);
  186.             commodDepth = Scr->BitMap.Depth;
  187.             commodGadgetTags[18] = Scr->BitMap.Depth;
  188.             for ( loop=0 ; loop<11 ; loop++ )
  189.                 {
  190.                 CopyMem((char * )&commodNewGadgets[loop], ( char * )&newgad, (long)sizeof( struct NewGadget ));
  191.                 newgad.ng_VisualInfo = commodVisualInfo;
  192.                 newgad.ng_LeftEdge = newgad.ng_LeftEdge*scalex/65535;
  193.                 newgad.ng_TopEdge = newgad.ng_TopEdge*scaley/65535;
  194.                 if (commodGadgetTypes[loop] != GENERIC_KIND)
  195.                     {
  196.                     newgad.ng_Width = newgad.ng_Width*scalex/65535;
  197.                     newgad.ng_Height = newgad.ng_Height*scaley/65535;
  198.                     };
  199.                 newgad.ng_TextAttr = Scr->Font;
  200.                 newgad.ng_LeftEdge += offx;
  201.                 newgad.ng_TopEdge += offy;
  202.                 commodGadgets[ newgad.ng_GadgetID - commodFirstID ] = Gad = CreateGadgetA( commodGadgetTypes[loop], Gad, &newgad, newgad.ng_UserData );
  203.                 }
  204.             if (Gad != NULL)
  205.                 {
  206.                 if (NULL != (commod = OpenWindowTags( NULL, WA_Left, 0,
  207.                                 WA_Top, 11,
  208.                                 WA_Width, 502*scalex/65535+offx,
  209.                                 WA_Height, 93*scaley/65535+offy,
  210.                                 WA_Title, "StickIt2 ©1994 Andy Dean",
  211.                                 WA_ScreenTitle, "StickIt2 ©1994 Andy Dean",
  212.                                 WA_MinWidth, 150,
  213.                                 WA_MinHeight, 25,
  214.                                 WA_MaxWidth, 1200,
  215.                                 WA_MaxHeight, 1200,
  216.                                 WA_DragBar, TRUE,
  217.                                 WA_DepthGadget, TRUE,
  218.                                 WA_CloseGadget, TRUE,
  219.                                 WA_Activate, TRUE,
  220.                                 WA_Dummy+0x30, TRUE,
  221.                                 WA_SmartRefresh, TRUE,
  222.                                 WA_AutoAdjust, TRUE,
  223.                                 WA_Gadgets, commodGList,
  224.                                 TAG_END)))
  225.                     {
  226.                     commod->UserPort = mp;
  227.                     ModifyIDCMP( commod, 6292348);
  228.                     GT_RefreshWindow( commod, NULL);
  229.                     UnlockPubScreen( NULL, Scr);
  230.                     if (commodMenu == NULL)
  231.                         MakeMenucommodMenu( commodVisualInfo);
  232.                     if (commodMenu != NULL)
  233.                         {
  234.                         SetMenuStrip( commod, commodMenu);
  235.                         return( 0L );
  236.                         }
  237.                     CloseWindowSafely( commod );
  238.                     }
  239.                 }
  240.             FreeGadgets( commodGList);
  241.             FreeVisualInfo( commodVisualInfo );
  242.             }
  243.         UnlockPubScreen( NULL, Scr);
  244.         }
  245.     }
  246. else
  247.     {
  248.     WindowToFront(commod);
  249.     ActivateWindow(commod);
  250.     return( 0L );
  251.     }
  252. return( 1L );
  253. }
  254.  
  255. void CloseWindowcommod( void )
  256. {
  257. if (commod != NULL)
  258.     {
  259.     ClearMenuStrip( commod);
  260.     FreeMenus( commodMenu);
  261.     commodMenu = NULL;
  262.     CloseWindowSafely( commod);
  263.     commod = NULL;
  264.     FreeVisualInfo( commodVisualInfo);
  265.     FreeGadgets( commodGList);
  266.     }
  267. }
  268.  
  269. void StripIntuiMessages( struct MsgPort *mp, struct Window *win)
  270. {
  271. struct IntuiMessage *msg;
  272. struct Node *succ;
  273. msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  274. while (succ = msg->ExecMessage.mn_Node.ln_Succ)
  275.     {
  276.     if (msg->IDCMPWindow == win)
  277.         {
  278.         Remove(msg);
  279.         ReplyMsg(msg);
  280.         }
  281.     msg = (struct IntuiMessage *)succ;
  282.     }
  283. }
  284.  
  285. void CloseWindowSafely( struct Window *win)
  286. {
  287.     Forbid();
  288.     StripIntuiMessages( win->UserPort, win);
  289.     win->UserPort = NULL;
  290.     ModifyIDCMP( win, 0L);
  291.     Permit();
  292.     CloseWindow( win);
  293. }
  294.  
  295.